package edu.guigu.networkdemomvvm.nonsingle;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.util.List;

import edu.guigu.networkdemomvvm.nonsingle.User;
import edu.guigu.networkdemomvvm.network.GithubClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RequestViewModel extends ViewModel {

    public MutableLiveData<List<User>> responseLiveData = new MutableLiveData<>();

    public void remoteUserList(){
        Call<List<User>> call = GithubClient.getInstance().listUsers();
        call.enqueue(new Callback<List<User>>() {
            @Override
            public void onResponse(Call<List<User>> call, Response<List<User>> response) {
                responseLiveData.setValue(response.body());
            }

            @Override
            public void onFailure(Call<List<User>> call, Throwable t) {
                Log.d("TAG", "onFailure: "+t.getMessage());
            }
        });
    }
}
